package com.jic.data.service.impl;
import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.date.DateUtil;
import com.jic.data.model.vo.response.HistogramChartResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.jic.data.model.entity.MonProductSaleAmount;
import com.jic.data.mapper.MonProductSaleAmountMapper;
import com.jic.data.service.MonProductSaleAmountService;

import lombok.extern.slf4j.Slf4j;
/**
 * 接口实现类
 *
 * @author : 建投数据科技(山东)有限公司
 * @version : v1.0.0
 * @email :
 * @since : 2020-03-09 10:12:20
 */
@Service
@Slf4j
public class MonProductSaleAmountServiceImpl implements MonProductSaleAmountService {

	@Resource
	private MonProductSaleAmountMapper mapper;




	/**
	 * 月度商品销售额&件单价
	 *
	 * @param request 不分页查询入参实体类
	 * @return 数据库查到的实体类列表
	 */
	@Override
	public HistogramChartResponse listAllRecord(MonProductSaleAmount request) {
		HistogramChartResponse response = new HistogramChartResponse();
		List<String> xDate = new ArrayList<>();
		List<Double> saleAmount = new ArrayList<>();
		List<Double> unitPrice = new ArrayList<>();
		List<MonProductSaleAmount> list = mapper.selectBySelective(request);
		list.sort((p1,p2) -> p1.getSaleDate().compareTo(p2.getSaleDate()));

		list.stream().forEach(amount -> {
			xDate.add(DateUtil.format(amount.getSaleDate(),"yyyy年MM"));
			saleAmount.add(amount.getTotalSaleAmount().doubleValue());
			unitPrice.add(amount.getUnitPrice().doubleValue());
		});
		response.setX(xDate);
		response.setY1(saleAmount);
		response.setY2(unitPrice);

		return response;
	}




}
